let app = getApp();
import dayjs from "../../../../common/js/dayjs.js";
import { gethouse } from "../../../../request/api.js";

Page({

    /**
     * 页面的初始数据
     */
    data: {
        lang: null,
        rentHousePageNo : 1,
        pageNo : 1,
        houseTotalPage: 1,
        houseBox: [],
        attributes: null,
        filterType: null
    },

    // 获取内容
    getPost() {
        let status = 1
        let type = this.data.filterType
        let attributes = this.data.attributes
        let data = { status, type, attributes,pageNo : this.data.pageNo }
        gethouse(res => {
            let request = res.data.data
            if (res.statusCode == 200) {
                for (let item of res.data.data) {
                    item.releaseTime = dayjs(item.releaseTime).format("YYYY-MM-DD")
                    item.price = parseInt(item.price, 10)
                }
                this.setData({ houseBox: this.data.houseBox.concat(request), houseTotalPage : res.data.totalPage})
            }
        }, data);
    },

    // 跳页到详细页面
    goDetailed(event) {
        let itemId = event.currentTarget.dataset.item.id
        wx.navigateTo({
            url: '/pages/home/house/houseDetaild/houseDetaild?itemId=' + itemId
        });
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({ lang: app.globalData.lang, navTitle: "housingInfo", navigation: true, filterType: options.filterType, attributes: options.attributes });
        this.getPost()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {
        if(this.data.currentIndex == 0){
            if(this.data.pageNo == this.data.houseTotalPage) return
            let pageNo = this.data.pageNo += 1
            this.setData({pageNo : pageNo})
            this.sellHouse();
        }else if(this.data.currentIndex == 1){
            if(this.data.rentHousePageNo == this.data.rentHouseTotalpage) return
            let pageNo = this.data.rentHousePageNo += 1
            this.setData({rentHousePageNo : pageNo})
            this.rentHouse();
        }
    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})